import socket

# 创建一个TCP socket对象
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 绑定服务器的IP地址和端口号
server_socket.bind(('localhost', 8888))

# 开始监听连接
server_socket.listen(1)

print('服务器已启动，等待客户端连接...')

# 等待客户端连接
client_socket, client_address = server_socket.accept()

print('客户端已连接，地址为：', client_address)

# 接收客户端发送的消息
data = client_socket.recv(1024)

# 打印接收到的消息
print('接收到的消息：', data.decode())

# 向客户端发送消息
client_socket.send('Hello, Client!'.encode())

# 关闭连接
client_socket.close()
server_socket.close()